    iv = os.urandom(16)  # 生成随机IV
    cipher = AES.new(KEY, AES.MODE_CBC, iv)
    return iv + cipher.encrypt(pad(data, AES.block_size))

# 创建TCP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 8888)
client_socket.connect(server_address)

# 读取并加密文件
file_path = 'original_file'  # 要发送的文件
with open(file_path, 'rb') as f:
    file_data = f.read()

encrypted_data = encrypt_message(file_data)

# 发送加密数据
client_socket.sendall(encrypted_data)
print("文件已加密并发送")

client_socket.close()